package net.zabuchy.customer.action;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.zabuchy.customer.bo.CustomerBo;
import net.zabuchy.customer.entity.Customer;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class ListAllCustomersAction extends ActionSupport implements
		ServletRequestAware, ServletResponseAware {
	
	/*@Autowired
	private SessionHelper sessionBean;*/
	@Autowired
	private CustomerBo customerBo;
	/*@Autowired
	private EmailHelper emailHelper;*/
	
	private Integer customerId;
	

	private List<Customer> customers;
	
	private HttpServletRequest request;
	private HttpServletResponse response;
	
	private static final Logger LOGGER = Logger.getLogger(CreateCustomerAction.class.getName());
	
	public String execute() {

		if (customerBo == null) {
            return Action.ERROR;
        }
		customers = customerBo.findAll();
		
		return Action.SUCCESS;
	}
	
	public String delete() {
        if (customerBo == null) {
            return Action.ERROR;
        }
 
        Customer cust = customerBo.findById(customerId);
        if (cust == null) {
            return Action.ERROR;
        }
 
        LOGGER.debug("Delete cust " + cust.getCustomerId());
        customerBo.delete(cust);
        return Action.SUCCESS;
    }
	
	
	
	public CustomerBo getCustomerBo() {
		return customerBo;
	}

	public void setCustomerBo(CustomerBo customerBo) {
		this.customerBo = customerBo;
	}

	public Integer getCustomerId() {
		return customerId;
	}

	public void setCustomerId(Integer customerId) {
		this.customerId = customerId;
	}

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public HttpServletRequest getRequest() {
		return request;
	}

	public void setRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletResponse getResponse() {
		return response;
	}

	public void setResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public HttpServletRequest getServletRequest() {
		return request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	public HttpServletResponse getServletResponse() {
		return response;
	}
}
